﻿package src.game {
	import flash.display.MovieClip;
	import flash.geom.Point;
	
	public class Crock extends MovieClip{
		private var horizontalMovement:Number = 0;
		private var verticalMovement:Number = 0;
		private var speed:int = 10;
		private var foodSpeed:int;
		
		public function Crock() {
			// constructor code
		}
		
		public function setFoodSpeed(value:int):void {
			this.foodSpeed = value;
		}
		
		public function update():void {
			this.x += horizontalMovement * speed;
			this.y += verticalMovement * speed;
		}
		
		public function updateFoodPosition(x:int, y:int):void {
			if ( (this.y - y < this.height + this.height / 2) && (this.y > this.parent.stage.stageHeight) ) {
				this.x = x;
				verticalMovement = -1;
			}
			else if ( (this.y - y >= this.height + this.height / 2) && (this.y <= this.parent.stage.stageHeight + this.height / 2) ) {
				this.x = x;
				verticalMovement = 0.3;
				if (this.currentFrame == 10) this.play();
			}
			else
				verticalMovement = 0;
			eat(y);
		}
		
		private function eat(y:int):void {
			var dist:int = this.y - this.height / 2 - y;
			if (dist < (foodSpeed * this.totalFrames) / 2 && this.currentFrame == 1)
				play();
		}
	}
	
}
